import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class Ztest 
{
	public static void main(String[] args) 
	{
		//get_tables("Northwind", "127.0.0.1", 1433, "miki", "miki");
		ArrayList<elem> lista = new ArrayList<elem>();
		polaczenia es = new polaczenia("127.0.0.1", 1433, "Northwind", "miki", "miki");
		lista = es.konwertuj_bazy_i_tabele_na_liste_list("127.0.0.1", 1433, "miki", "miki");
		lista_list.wypisz_liste_list(lista);
	}
	
	public static ArrayList<String> get_tables(String nazwa_bazy, String ip, int port, String login, String pass)
	{
	    try 
	    {
	    	ArrayList<String> lista_tabel = new ArrayList<String>();
			String connUrl = "jdbc:sqlserver://" + ip + ":" + port + ";databaseName=" + nazwa_bazy + ";user=" + login + ";password=" + pass;
			Connection conn = DriverManager.getConnection(connUrl);

		    DatabaseMetaData dmd = conn.getMetaData();
		    ResultSet rs1 = dmd.getSchemas();
		    while (rs1.next()) 
		    {
		      String ss = rs1.getString(1);
		      String[] types = {"TABLE"};
		      ResultSet rs2 = dmd.getTables(null, ss, "%", types);
		      while (rs2.next())
		      {
		    	  //System.out.println(rs2.getString(3));
		    	  lista_tabel.add(rs2.getString(3));
		      }
		    }
		    conn.close();
		    return lista_tabel;
	    }
	    catch (Exception e) 
	    {
			e.printStackTrace();
		}
	    return null;
	}
}
